package com.rimi.lzhg.controller;

import com.rimi.lzhg.entry.Type;
import com.rimi.lzhg.response.ResponseEntity;
import com.rimi.lzhg.service.TypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@CrossOrigin
@RestController
public class TypeController {

    @Autowired
    private TypeService typeService;

    @ApiOperation(value = "菜单类型列表",notes = "无条件查询所有的菜单类型")
    @GetMapping("/manager/type")
    public Object getManagerTypeList(){
        List<Type> typeList = typeService.getTypeList();
        return ResponseEntity.success(typeList.size(),typeList);
    }


    @ApiOperation(value = "菜单类型列表",notes = "无条件查询所有的菜单类型")
    @GetMapping("/type")
    public Object getTypeList(){
        return typeService.getTypeList();
    }

    @ApiOperation(value = "查询菜单类型",notes = "根据Id查询菜单类型url传地址id 如: /type/100")
    @GetMapping("/type/{id}")
    public Object getTypeById(@PathVariable Integer id){
        return typeService.getTypeById(id);
    }


    @ApiOperation(value = "添加菜单类型",notes = "添加菜单类型")
    @PostMapping("/type")
    public Object saveType(Type type){
        return typeService.addType(type);
    }

    @ApiOperation(value = "根据编号修改菜单类型",notes = "根据Id修改菜单信息")
    @PutMapping("/type")
    public Object updateType(Type type){
        return typeService.updateType(type);
    }

    @ApiOperation(value = "删除菜单类型",notes = "根据Id删除菜单类型")
    @DeleteMapping("/type")
    public Object deleteTypeById(Integer id){
        return typeService.deleteType(id);
    }



}
